package club.dingzm.myapplication.HttpBreakPoint;

import com.alibaba.fastjson.annotation.JSONField;

import java.io.File;
import java.io.Serializable;

public class BreakpointInfo implements Serializable {

    // 获取分块数据，按照每次1M的大小分块上传
    public static int CHUNK_SIZE = 5 * 1024 * 1024;

    //文件无法被序列化，设置为无需序列化
    @JSONField(serialize=false)
    private File file;

    private String tempFile;//文件分片文件夹
    //文件路径
    private String filePath ;
    //文件长度
    private long fileLength ;
    //当前发送位置
    private int currentBlock ;
    //当前发送位置
    private String md5Hsh ;

    // 获取分块数据，分为的块数
    int BLOCK_SIZE = 0;
    // 数据上传 是否成功，
    private Boolean success = null ;

    public BreakpointInfo() {
    }

    public BreakpointInfo(String filePath) {
        this.filePath = filePath;
        BLOCK_SIZE = 0;
        file = new File(filePath);
        md5Hsh = MD5Util.getFileMD5String(filePath);
        fileLength = file.length();
        BLOCK_SIZE= (int) Math.ceil( fileLength * 1.0 / BreakpointInfo.CHUNK_SIZE);
        currentBlock = 0;

    }

    public File getFile() {
        return file;
    }

    private void setFile(File file) {
        this.file = file;
    }

    public String getTempFile() {
        return tempFile;
    }

    public void setTempFile(String tempFile) {
        this.tempFile = tempFile;
        File file1 = new File(this.tempFile);
        if ( !file1.exists()){
            file1.mkdir();
        }
    }

    public String getFilePath() {
        return filePath;

    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
        file = new File(filePath);
    }

    public long getFileLength() {
        return fileLength;
    }

    public void setFileLength(long fileLength) {
        this.fileLength = fileLength;
    }

    public int getCurrentBlock() {
        return currentBlock;
    }

    public void setCurrentBlock(int currentBlock) {
        this.currentBlock = currentBlock;
    }

    public int getBLOCK_SIZE() {
        return BLOCK_SIZE;
    }

    public void setBLOCK_SIZE(int BLOCK_SIZE) {
        this.BLOCK_SIZE = BLOCK_SIZE;
    }

    public String getMd5Hsh() {
        return md5Hsh;
    }

    public void setMd5Hsh(String md5Hsh) {
        this.md5Hsh = md5Hsh;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
